import time

# 未优化的递归代码
def unoptimized_fibonacci(n):
    if n <= 1:
        return n
    else:
        return unoptimized_fibonacci(n-1) + unoptimized_fibonacci(n-2)

# 优化后的迭代代码
def optimized_fibonacci(n):
    a, b = 0, 1
    for _ in range(n):
        a, b = b, a + b
    return a

if __name__ == "__main__":
    n = 35
    start_time = time.time()
    result = unoptimized_fibonacci(n)
    end_time = time.time()
    print(f"Unoptimized Fibonacci({n}) took {end_time - start_time:.6f} seconds, result: {result}")

    start_time = time.time()
    result = optimized_fibonacci(n)
    end_time = time.time()
    print(f"Optimized Fibonacci({n}) took {end_time - start_time:.6f} seconds, result: {result}")